﻿#include "http_client.h"

HTTP_client::HTTP_client(QObject *parent)
    :QObject(parent)
{
    m_requestTimeoutTimer = new QTimer(&nam);
}


bool HTTP_client::PostRequest(QString key, QString data){

    QJsonObject dataobj;

    dataobj.insert("MachineSn","Taikan 2208377");
    dataobj.insert("CMD","get");

    QJsonDocument document;
    document.setObject(dataobj);

    QByteArray byte_array = document.toJson(QJsonDocument::Compact);

    //http请求

    QNetworkRequest request1;

    QNetworkAccessManager nam;

    //connect(&nam,&QNetworkAccessManager::finished, this, &HTTP_client::receivePostReply);

    request1.setUrl(QUrl("http://10.120.1.58/api/Opration/OperateCloseDoor"));

    request1.setHeader(QNetworkRequest::ContentTypeHeader,
                       QVariant("application/json;charset=utf-8"));

    QNetworkReply* reply = nam.post(request1,byte_array);


    http_time_.start();
    QEventLoop loop;
    connect(reply,&QNetworkReply::finished,&loop,&QEventLoop::quit);
    loop.exec();
    qDebug()<<http_time_.elapsed()/1000.0<<"s";

    if(reply->error() != QNetworkReply::NoError)
    {
        qDebug() << "error msg "
                 << reply->errorString();
    }

    //
    QByteArray responseByte = reply->readAll();
    QString strRes = responseByte;
    qDebug() << "Post: " << strRes;


    // parse command
    bool result = false;
    QJsonParseError jsonError;
    QJsonDocument parseResponse = QJsonDocument::fromJson(responseByte, &jsonError);
    if (!parseResponse.isNull() && (jsonError.error == QJsonParseError::NoError))
    {
        QJsonObject object = parseResponse.object();
        if (object.contains("Flag"))
        {
            QJsonValue value = object["Flag"];

            bool value_string = value.toBool();

            qDebug() << "value " << value_string;

            return value_string;
        }
        else{
            return false;
        }
    }
    else{
        return false;
    }



}

QString HTTP_client::receivePostReply(QNetworkReply *reply){
    QString res = reply->readAll();
    return res;
}

//true 是开门， false是关门 ，目前没有用到
bool HTTP_client::get_door_state(QString MachineSn,int& error){
    QJsonObject dataobj;

    dataobj.insert("MachineSn","Taikan " + MachineSn);
    dataobj.insert("CMD","get");

    QJsonDocument document;
    document.setObject(dataobj);

    QByteArray byte_array = document.toJson(QJsonDocument::Compact);

    //http请求

    QNetworkRequest request;

    request.setUrl(QUrl("http://10.120.1.58/api/Opration/OperateOpenDoor"));

    request.setHeader(QNetworkRequest::ContentTypeHeader,
                      QVariant("application/json;charset=utf-8"));

    QNetworkReply* reply = nam.post(request,byte_array);

    m_requestTimeoutTimer->setSingleShot(true);// 单次触发
    m_requestTimeoutTimer->setInterval(15000);

    http_time_.start();
    QEventLoop loop;
    connect(m_requestTimeoutTimer,&QTimer::timeout,&loop,&QEventLoop::quit);
    connect(reply,&QNetworkReply::finished,&loop,&QEventLoop::quit);
    m_requestTimeoutTimer->start();
    loop.exec();
    qDebug()<<http_time_.elapsed()/1000.0<<"s";

    if(m_requestTimeoutTimer->isActive()){
        m_requestTimeoutTimer->stop();
        //错误处理
        if (reply->error() == QNetworkReply::NoError)
        {
            //qDebug() << "request protobufHttp NoError";
        }
        else
        {
            qDebug()<<"request protobufHttp handle errors here";
            QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
            qDebug() << "request protobufHttp found error ....code: %d %d\n" << statusCodeV.toInt() << (int)reply->error();
            qDebug() << "request error fail:" << reply->errorString();
            //异常处理
            return false;
        }

    }else{
        disconnect(m_requestTimeoutTimer,&QTimer::timeout,&loop,&QEventLoop::quit);
        //超时处理
        qDebug() << "request time out";
        return false;
    }

    /*
    if(reply->error() != QNetworkReply::NoError)
    {
        qDebug() << "error msg "
                 << reply->errorString();
    }*/

    //
    QByteArray responseByte = reply->readAll();
    QString strRes = responseByte;
    qDebug() << "Post: " << strRes;

    // parse command
    QJsonParseError jsonError;
    QJsonDocument parseResponse = QJsonDocument::fromJson(responseByte, &jsonError);
    if (!parseResponse.isNull() && (jsonError.error == QJsonParseError::NoError))
    {
        QJsonObject object = parseResponse.object();
        if (object.contains("Flag"))
        {
            QJsonValue value = object["Flag"];
            bool value_flag = value.toBool();
            qDebug() << "value_flag " << value_flag;

            value = object["Message"];
            QString value_string = value.toString();
            qDebug() << "value_string " << value_string;

            value = object["Data"];
            int value_data = value.toInt();
            qDebug() << "value_data " << value_data;

            return value_flag;
        }
        else{
            return false;
        }
    }
    else{
        return false;
    }


}

//设置吹气
bool HTTP_client::operate_blow(QString MachineSn, int& error){

    QJsonObject dataobj;
    dataobj.insert("MachineSn","Taikan " + MachineSn);
    dataobj.insert("CMD","set");

    QJsonDocument document;
    document.setObject(dataobj);

    QByteArray byte_array = document.toJson(QJsonDocument::Compact);

    //http请求

    QNetworkRequest request;

    request.setUrl(QUrl("http://10.120.1.58/api/Opration/OperaterBlow"));

    request.setHeader(QNetworkRequest::ContentTypeHeader,
                      QVariant("application/json;charset=utf-8"));

    QNetworkReply* reply = nam.post(request,byte_array);

    m_requestTimeoutTimer->setSingleShot(true);// 单次触发
    m_requestTimeoutTimer->setInterval(15000);

    //http_time_.start();
    qDebug() << "wait for reply ...";
    QEventLoop loop;
    connect(m_requestTimeoutTimer,&QTimer::timeout,&loop,&QEventLoop::quit);
    connect(reply,&QNetworkReply::finished,&loop,&QEventLoop::quit);
    m_requestTimeoutTimer->start();
    loop.exec();
    //qDebug()<<http_time_.elapsed()/1000.0<<"s";

    if(m_requestTimeoutTimer->isActive()){
        m_requestTimeoutTimer->stop();
        //错误处理
        if (reply->error() == QNetworkReply::NoError)
        {
            //qDebug() << "request protobufHttp NoError";
        }
        else
        {
            qDebug()<<"request protobufHttp handle errors here";
            QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
            qDebug() << "request protobufHttp found error ....code: %d %d\n" << statusCodeV.toInt() << (int)reply->error();
            qDebug() << "request error fail:" << reply->errorString();
            return false;
        }

    }else{
        //接着执行正常流程
        disconnect(m_requestTimeoutTimer,&QTimer::timeout,&loop,&QEventLoop::quit);
        //超时处理，返回关门状态
        qDebug() << "request time out";

        //一直查询，直到查询到结果
        /*
        while(1){
            qDebug() << "get operator blow state ...";
            int timeout = 0;
            bool get_state = get_operate_blow_state(MachineSn, timeout);

            //没有超时，可以进行判断
            if(timeout == 0){

                //已经清洗完成
                if(get_state == true){
                    qDebug() << "超时后吹气检测，已完成";
                    return true;
                }
                else{
                    qDebug() << "超时后吹气检测，未完成";
                    return false;
                }

                break;
            }
        }
        */

        return false;
    }

    /*
    if(reply->error() != QNetworkReply::NoError)
    {
        qDebug() << "error msg "
                 << reply->errorString();
    }*/

    //
    QByteArray responseByte = reply->readAll();
    QString strRes = responseByte;
    qDebug() << "Post: " << strRes;

    // parse command
    QJsonParseError jsonError;
    QJsonDocument parseResponse = QJsonDocument::fromJson(responseByte, &jsonError);
    if (!parseResponse.isNull() && (jsonError.error == QJsonParseError::NoError))
    {
        QJsonObject object = parseResponse.object();
        if (object.contains("Flag"))
        {
            QJsonValue value = object["Flag"];
            bool value_flag = value.toBool();
            qDebug() << "value_flag " << value_flag;

            value = object["Message"];
            QString value_string = value.toString();
            qDebug() << "value_string " << value_string;

            value = object["Data"];
            int value_data = value.toInt();
            qDebug() << "value_data " << value_data;

            return value_flag;
        }
        else{
            return false;
        }
    }
    else{
        return false;
    }


}

bool HTTP_client::get_operate_blow_state(QString MachineSn, int& timeout){

    QJsonObject dataobj;
    dataobj.insert("MachineSn","Taikan " + MachineSn);
    dataobj.insert("CMD","get");

    QJsonDocument document;
    document.setObject(dataobj);

    QByteArray byte_array = document.toJson(QJsonDocument::Compact);

    //http请求

    QNetworkRequest request;

    request.setUrl(QUrl("http://10.120.1.58/api/Opration/OperaterBlow"));

    request.setHeader(QNetworkRequest::ContentTypeHeader,
                      QVariant("application/json;charset=utf-8"));

    QNetworkReply* reply = nam.post(request,byte_array);

    m_requestTimeoutTimer->setSingleShot(true);// 单次触发
    m_requestTimeoutTimer->setInterval(15000);

    //http_time_.start();
    qDebug() << "get operatorBlow state for reply ...";
    QEventLoop loop;
    connect(m_requestTimeoutTimer,&QTimer::timeout,&loop,&QEventLoop::quit);
    connect(reply,&QNetworkReply::finished,&loop,&QEventLoop::quit);
    m_requestTimeoutTimer->start();
    loop.exec();
    //qDebug()<<http_time_.elapsed()/1000.0<<"s";

    if(m_requestTimeoutTimer->isActive()){
        m_requestTimeoutTimer->stop();
        //错误处理
        if (reply->error() == QNetworkReply::NoError)
        {
            //qDebug() << "request protobufHttp NoError";
        }
        else
        {
            qDebug()<<"request protobufHttp handle errors here";
            QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
            qDebug() << "request protobufHttp found error ....code: %d %d\n" << statusCodeV.toInt() << (int)reply->error();
            qDebug() << "request error fail:" << reply->errorString();
            return false;
        }

    }else{
        //接着执行正常流程
        disconnect(m_requestTimeoutTimer,&QTimer::timeout,&loop,&QEventLoop::quit);
        //超时处理，返回关门状态
        qDebug() << "request time out";
        timeout = 1;
        return false;
    }

    /*
    if(reply->error() != QNetworkReply::NoError)
    {
        qDebug() << "error msg "
                 << reply->errorString();
    }*/

    //
    QByteArray responseByte = reply->readAll();
    QString strRes = responseByte;
    qDebug() << "Post: " << strRes;

    // parse command
    QJsonParseError jsonError;
    QJsonDocument parseResponse = QJsonDocument::fromJson(responseByte, &jsonError);
    if (!parseResponse.isNull() && (jsonError.error == QJsonParseError::NoError))
    {
        QJsonObject object = parseResponse.object();
        if (object.contains("Flag"))
        {
            QJsonValue value = object["Flag"];
            bool value_flag = value.toBool();
            qDebug() << "value_flag " << value_flag;

            value = object["Message"];
            QString value_string = value.toString();
            qDebug() << "value_string " << value_string;

            value = object["Data"];
            int value_data = value.toInt();
            qDebug() << "value_data " << value_data;

            if(value_data == 0){
                 //清洗完成
                return true;
            }
            else{
                //清洗未完成
                return false;
            }

        }
        else{
            return false;
        }
    }
    else{
        return false;
    }
}


//获取机台加工状态
bool HTTP_client::operate_get_status(QString MachineSn, int& state){


    QJsonObject dataobj;

    QJsonArray MachineSnArray;
    MachineSnArray.push_back("Taikan " + MachineSn);

    dataobj.insert("MachineSn",MachineSnArray);

    QJsonDocument document;
    document.setObject(dataobj);

    QByteArray byte_array = document.toJson(QJsonDocument::Compact);

    //http请求

    QNetworkRequest request;

    request.setUrl(QUrl("http://10.120.1.58/api/Opration/OperateGetStatus"));

    request.setHeader(QNetworkRequest::ContentTypeHeader,
                      QVariant("application/json;charset=utf-8"));

    QNetworkReply* reply = nam.post(request,byte_array);

    m_requestTimeoutTimer->setSingleShot(true);// 单次触发
    m_requestTimeoutTimer->setInterval(15000);

    http_time_.start();
    QEventLoop loop;
    connect(m_requestTimeoutTimer,&QTimer::timeout,&loop,&QEventLoop::quit);
    connect(reply,&QNetworkReply::finished,&loop,&QEventLoop::quit);
    m_requestTimeoutTimer->start();
    loop.exec();
    //qDebug()<<http_time_.elapsed()/1000.0<<"s";

    if(m_requestTimeoutTimer->isActive()){
        m_requestTimeoutTimer->stop();
        //错误处理
        if (reply->error() == QNetworkReply::NoError)
        {
            //qDebug() << "request protobufHttp NoError";
        }
        else
        {
            qDebug()<<"request protobufHttp handle errors here";
            QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
            qDebug() << "request protobufHttp found error ....code: %d %d\n" << statusCodeV.toInt() << (int)reply->error();
            qDebug() << "request error fail:" << reply->errorString();
            return false;
        }

    }else{
        //接着执行正常流程
        disconnect(m_requestTimeoutTimer,&QTimer::timeout,&loop,&QEventLoop::quit);
        //超时处理，返回关门状态
        qDebug() << "request time out";
        return false;
    }

    /*
    if(reply->error() != QNetworkReply::NoError)
    {
        qDebug() << "error msg "
                 << reply->errorString();
    }*/

    //
    QByteArray responseByte = reply->readAll();
    QString strRes = responseByte;
    qDebug() << "Post: " << strRes;

    // parse command
    QJsonParseError jsonError;
    QJsonDocument parseResponse = QJsonDocument::fromJson(responseByte, &jsonError);
    if (!parseResponse.isNull() && (jsonError.error == QJsonParseError::NoError))
    {
        QJsonObject object = parseResponse.object();
        if (object.contains("Flag"))
        {
            QJsonValue value = object["Flag"];
            bool value_flag = value.toBool();
            //qDebug() << "value_flag " << value_flag;

            value = object["Message"];
            QString value_string = value.toString();
            //qDebug() << "value_string " << value_string;

            QJsonValue jvalue = object["Data"];

            if(jvalue.isArray()){
                QJsonArray array = jvalue.toArray();

                int nSize = array.size();

                for(int i=0; i < nSize; ++i){
                    QJsonValue value = array.at(i);
                    if(value.isObject()){
                        QJsonObject value_item = value.toObject();

                        int status = -1;
                        if(value_item.contains("Status")){
                            QJsonValue value = value_item["Status"];
                            status = value.toInt();
                        }

                        QString MachineCode;
                        if(value_item.contains("MachineCode")){
                            QJsonValue value = value_item["MachineCode"];
                            MachineCode = value.toString();
                        }

                        QString CheckSn = "Taikan " + MachineSn;
                        if(MachineCode == CheckSn){
                            state = status;
                            //qDebug() << "MachineCode " << MachineCode
                            //         << " status "  << status;
                            break;
                        }
                    }
                }

            }


            return value_flag;
        }
        else{
            return false;
        }
    }
    else{
        return false;
    }


}

//上传DM码
bool HTTP_client::upload_dm_message(QString deviceSN,QString pieceNumber){

    QJsonObject dataobj;
    dataobj.insert("identifyingCode","Taikan " + deviceSN);
    dataobj.insert("pieceNumber",pieceNumber);
    dataobj.insert("sourceFlag",0);

    QJsonDocument document;
    document.setObject(dataobj);

    QByteArray byte_array = document.toJson(QJsonDocument::Compact);

    qDebug() << "byte_array " << byte_array;

    //http请求

    QNetworkRequest request;

    request.setUrl(QUrl("http://10.120.1.41:8080/external/knifeCabinet/qrCodeScanning"));

    request.setHeader(QNetworkRequest::ContentTypeHeader,
                      QVariant("application/json;charset=utf-8"));

    QNetworkReply* reply = nam.post(request,byte_array);

    m_requestTimeoutTimer->setSingleShot(true);// 单次触发
    m_requestTimeoutTimer->setInterval(15000);

    http_time_.start();
    QEventLoop loop;
    connect(m_requestTimeoutTimer,&QTimer::timeout,&loop,&QEventLoop::quit);
    connect(reply,&QNetworkReply::finished,&loop,&QEventLoop::quit);
    m_requestTimeoutTimer->start();
    loop.exec();
    //qDebug()<<http_time_.elapsed()/1000.0<<"s";

    if(m_requestTimeoutTimer->isActive()){
        m_requestTimeoutTimer->stop();
        //错误处理
        if (reply->error() == QNetworkReply::NoError)
        {
            //qDebug() << "request protobufHttp NoError";
        }
        else
        {
            qDebug()<<"request protobufHttp handle errors here";
            QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
            qDebug() << "request protobufHttp found error ....code: %d %d\n" << statusCodeV.toInt() << (int)reply->error();
            qDebug() << "request error fail:" << reply->errorString();
            return false;
        }

    }else{
        //接着执行正常流程
        disconnect(m_requestTimeoutTimer,&QTimer::timeout,&loop,&QEventLoop::quit);
        //超时处理，返回关门状态
        qDebug() << "request time out";
        return false;
    }

    /*
    if(reply->error() != QNetworkReply::NoError)
    {
        qDebug() << "error msg "
                 << reply->errorString();
    }*/

    //
    QByteArray responseByte = reply->readAll();
    QString strRes = responseByte;
    qDebug() << "responseByte: " << responseByte;

    // parse command
    QJsonParseError jsonError;
    QJsonDocument parseResponse = QJsonDocument::fromJson(responseByte, &jsonError);
    if (!parseResponse.isNull() && (jsonError.error == QJsonParseError::NoError))
    {
        QJsonObject object = parseResponse.object();
        if (object.contains("code"))
        {
            QJsonValue value = object["code"];
            int value_flag = value.toInt();
            //qDebug() << "value_flag " << value_flag;

            value = object["msg"];
            QString value_string = value.toString();
            //qDebug() << "value_string " << value_string;

            if(value_flag == 200){
                return true;
            }
            else{
                return false;
            }
        }
        else{
            return false;
        }
    }
    else{
        return false;
    }

}


//开门，目前流程没有用到
bool HTTP_client::operate_open_door(QString MachineSn,int& error){
    QJsonObject dataobj;

    dataobj.insert("MachineSn","Taikan " + MachineSn);
    dataobj.insert("CMD","set");

    QJsonDocument document;
    document.setObject(dataobj);

    QByteArray byte_array = document.toJson(QJsonDocument::Compact);

    //http请求

    QNetworkRequest request;

    request.setUrl(QUrl("http://10.120.1.58/api/Opration/OperateOpenDoor"));

    request.setHeader(QNetworkRequest::ContentTypeHeader,
                      QVariant("application/json;charset=utf-8"));

    QNetworkReply* reply = nam.post(request,byte_array);

    m_requestTimeoutTimer->setSingleShot(true);// 单次触发
    m_requestTimeoutTimer->setInterval(15000);

    http_time_.start();
    QEventLoop loop;
    connect(m_requestTimeoutTimer,&QTimer::timeout,&loop,&QEventLoop::quit);
    connect(reply,&QNetworkReply::finished,&loop,&QEventLoop::quit);
    m_requestTimeoutTimer->start();
    loop.exec();
    qDebug()<<http_time_.elapsed()/1000.0<<"s";

    if(m_requestTimeoutTimer->isActive()){
        m_requestTimeoutTimer->stop();
        //错误处理
        if (reply->error() == QNetworkReply::NoError)
        {
            //qDebug() << "request protobufHttp NoError";
        }
        else
        {
            qDebug()<<"request protobufHttp handle errors here";
            QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
            qDebug() << "request protobufHttp found error ....code: %d %d\n" << statusCodeV.toInt() << (int)reply->error();
            qDebug() << "request error fail:" << reply->errorString();
            return false;
        }

    }else{
        //接着执行正常流程
        disconnect(m_requestTimeoutTimer,&QTimer::timeout,&loop,&QEventLoop::quit);
        //超时处理，返回关门状态
        qDebug() << "request time out";
        return false;
    }

    /*
    if(reply->error() != QNetworkReply::NoError)
    {
        qDebug() << "error msg "
                 << reply->errorString();
    }*/

    //
    QByteArray responseByte = reply->readAll();
    QString strRes = responseByte;
    qDebug() << "Post: " << strRes;

    // parse command
    QJsonParseError jsonError;
    QJsonDocument parseResponse = QJsonDocument::fromJson(responseByte, &jsonError);
    if (!parseResponse.isNull() && (jsonError.error == QJsonParseError::NoError))
    {
        QJsonObject object = parseResponse.object();
        if (object.contains("Flag"))
        {
            QJsonValue value = object["Flag"];
            bool value_flag = value.toBool();
            qDebug() << "value_flag " << value_flag;

            value = object["Message"];
            QString value_string = value.toString();
            qDebug() << "value_string " << value_string;

            value = object["Data"];
            int value_data = value.toInt();
            qDebug() << "value_data " << value_data;

            return value_flag;
        }
        else{
            return false;
        }
    }
    else{
        return false;
    }
}

//关门
bool HTTP_client::operate_close_door(QString MachineSn,int& error){
    QJsonObject dataobj;

    dataobj.insert("MachineSn","Taikan " + MachineSn);
    dataobj.insert("CMD","set");

    QJsonDocument document;
    document.setObject(dataobj);

    QByteArray byte_array = document.toJson(QJsonDocument::Compact);

    //http请求

    QNetworkRequest request;

    request.setUrl(QUrl("http://10.120.1.58/api/Opration/OperateCloseDoor"));

    request.setHeader(QNetworkRequest::ContentTypeHeader,
                      QVariant("application/json;charset=utf-8"));

    QNetworkReply* reply = nam.post(request,byte_array);

    m_requestTimeoutTimer->setSingleShot(true);// 单次触发
    m_requestTimeoutTimer->setInterval(15000);

    http_time_.start();
    QEventLoop loop;
    connect(m_requestTimeoutTimer,&QTimer::timeout,&loop,&QEventLoop::quit);
    connect(reply,&QNetworkReply::finished,&loop,&QEventLoop::quit);
    m_requestTimeoutTimer->start();
    loop.exec();
    qDebug()<<http_time_.elapsed()/1000.0<<"s";

    if(m_requestTimeoutTimer->isActive()){
        m_requestTimeoutTimer->stop();
        //错误处理
        if (reply->error() == QNetworkReply::NoError)
        {
            //qDebug() << "request protobufHttp NoError";
        }
        else
        {
            qDebug()<<"request protobufHttp handle errors here";
            QVariant statusCodeV = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
            qDebug() << "request protobufHttp found error ....code: %d %d\n" << statusCodeV.toInt() << (int)reply->error();
            qDebug() << "request error fail:" << reply->errorString();
            return false;
        }

    }else{
        //接着执行正常流程
        disconnect(m_requestTimeoutTimer,&QTimer::timeout,&loop,&QEventLoop::quit);
        //超时处理，返回关门状态
        qDebug() << "request time out";
        return false;
    }

    /*
    if(reply->error() != QNetworkReply::NoError)
    {
        qDebug() << "error msg "
                 << reply->errorString();
    }*/

    //
    QByteArray responseByte = reply->readAll();
    QString strRes = responseByte;
    qDebug() << "Post: " << strRes;

    // parse command
    QJsonParseError jsonError;
    QJsonDocument parseResponse = QJsonDocument::fromJson(responseByte, &jsonError);
    if (!parseResponse.isNull() && (jsonError.error == QJsonParseError::NoError))
    {
        QJsonObject object = parseResponse.object();
        if (object.contains("Flag"))
        {
            QJsonValue value = object["Flag"];
            bool value_flag = value.toBool();
            qDebug() << "value_flag " << value_flag;

            value = object["Message"];
            QString value_string = value.toString();
            qDebug() << "value_string " << value_string;

            value = object["Data"];
            int value_data = value.toInt();
            qDebug() << "value_data " << value_data;

            return value_flag;
        }
        else{
            return false;
        }
    }
    else{
        return false;
    }
}

